package com.cn.web.user.service.impl;

import com.cn.user.UserUnitDO;
import com.cn.util.SnowflakeIdWorkerUtil;
import com.cn.web.user.mapper.IUserUnitMapper;
import com.cn.web.user.service.UserUnitService;
import com.cn.web.user.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * description: UserUnitService <br>
 * date: 21.12.16 17:09 <br>
 * author: cn_yaojin <br>
 * version: 1.0 <br>
 */
@Service
public class UserUnitServiceImpl implements UserUnitService {

    @Autowired
    private IUserUnitMapper iUserUnitMapper;

    @Override
    public void del(String userId) {
        Map<String, Object> pd = new HashMap<>();
        pd.put("user_id", userId);
        this.iUserUnitMapper.deleteByMap(pd);
    }

    @Override
    public void add(UserUnitDO userUnitEntity) {
        userUnitEntity.setId(SnowflakeIdWorkerUtil.getId());
        this.iUserUnitMapper.insert(userUnitEntity);
    }

    @Override
    public List<UserUnitDO> listByUserId(String userId) {
        Map<String, Object> pd = new HashMap<>();
        pd.put("user_id", userId);
        return this.iUserUnitMapper.selectByMap(pd);
    }

    @Override
    public List<UserUnitDO> listByUnitId(String userId) {
        Map<String, Object> pd = new HashMap<>();
        pd.put("unit_id", userId);
        return this.iUserUnitMapper.selectByMap(pd);
    }

    @Override
    public List<UserVO> listByUnit(String unitId) {
        return this.iUserUnitMapper.listByUnit(unitId);
    }
}
